import java.util.Calendar;

public class DaysInMonthExample {

    public static int getDaysInMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1); // 注意这里月份是从0开始计数
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    public static void main(String[] args){
        System.out.println(getDaysInMonth(2023, 9)); 
    }
}